<!DOCTYPE html>
<html>

	<head>
		<meta charset="UTF-8">
		<title>发布商品</title>
		<link rel="stylesheet" href="__AGENT__/css/css.css" />
		<script type="text/javascript" src="__PUBLIC__/static/js/jquery.min.js"></script>
		<link rel="stylesheet" href="__PUBLIC__/static/layui/css/layui.css">
		<script src="__PUBLIC__/static/layui/layui.js"></script>
	</head>

	<body>
		<form id="my_form" style="margin-bottom: 100px;" class="layui-form update_form" action="{:url('shop/goods_add')}" method="post">
			<div class="layui-form-item">
				<label class="layui-form-label">商品编码</label>
				<div class="layui-input-block update_shurk">
					<input type="text" name="goods_sn" lay-verify="goods_no" placeholder="商品编码" autocomplete="off" class="layui-input">
				</div>
			</div>
			<div class="layui-form-item">
				<label class="layui-form-label">*商品名称</label>
				<div class="layui-input-block update_shurk">
					<input type="text" name="goods_name" lay-verify="required" placeholder="商品名称" autocomplete="off" class="layui-input">
				</div>
			</div>
			<div class="layui-form-item">
				<label class="layui-form-label">*商品图片</label>
				<div class="layui-input-block" style="padding-left: 10px;">
					<img src="__PUBLIC__/static/images/timg.jpg" id="thumb_img" style="height: 150px;width: 250px;" />
					<input type="hidden" name="logo" id="thumb" />
					<input onchange="UploadFile('goods',200)" type="file" accept="image/*" id="file" name="file">
				</div>
			</div>

			<div class="layui-form-item">
				<label class="layui-form-label">*商品类别</label>
				<div class="layui-input-block" style="float: left; margin-right: 20px; margin-left: 0;">
					<select name="trade_id" id='trade_id' lay-verify="required" lay-filter="sel_1">
						<option value=""></option>
						{volist name="agent_type" id="vo"}
						<option value="{$vo.id}">{$vo.name}</option>
						{/volist}
					</select>
				</div>
			</div>
			<div class="layui-form-item">
				<label class="layui-form-label">*成本价</label>
				<div class="layui-input-block update_shurk" style="width: 80px; margin-right: 10px;">
					<input onkeyup="keyup(this)" type="text" name="cost_price" id="cost_price" placeholder="成本价" class="layui-input" onkeyup="value=value.replace(/[^\d\.]/g,'')" onblur="value=value.replace(/[^\d\.]/g,'')">
				</div>
				<div class="layui-form-mid layui-word-aux">元</div>
				<label class="layui-form-label">*零售价</label>
				<div class="layui-input-block update_shurk" style="width: 80px; margin-right: 10px;">
					<input onkeyup="keyup(this)" type="text" name="sale_price" id="sale_price" placeholder="零售价" class="layui-input" onkeyup="value=value.replace(/[^\d\.]/g,'')" onblur="value=value.replace(/[^\d\.]/g,'')">
				</div>
				<div class="layui-form-mid layui-word-aux">元</div>
			</div>
			<div class="layui-form-item">
				<label class="layui-form-label">*分佣</label>
				<div class="layui-input-block update_shurk" style="width: 80px; margin-right: 10px;">
					<input onkeyup="keyup(this)" type="text" name="fen_price" id="fen_price" placeholder="多少元" class="layui-input" onkeyup="value=value.replace(/[^\d\.]/g,'')" onblur="value=value.replace(/[^\d\.]/g,'')">
				</div>
				<div class="layui-form-mid layui-word-aux">元,(90%创业会员，10%红包)</div>
				<label class="layui-form-label">推荐人</label>
				<div class="layui-input-block update_shurk" style="width: 80px; margin-right: 10px;">
					<input onkeyup="keyup(this)" type="text" name="tui_id" id="tui_id" placeholder="推荐人ID" class="layui-input" onkeyup="value=value.replace(/[^\d\.]/g,'')" onblur="value=value.replace(/[^\d\.]/g,'')">
				</div>
				<div class="layui-input-block update_shurk" style="width: 80px; margin-right: 10px;">
					<input onkeyup="keyup(this)" type="text" name="tui_price" id="tui_price" placeholder="多少元" class="layui-input" onkeyup="value=value.replace(/[^\d\.]/g,'')" onblur="value=value.replace(/[^\d\.]/g,'')">
				</div>
				<div class="layui-form-mid layui-word-aux">元</div>
			</div>
			<div class="layui-form-item">
				<label class="layui-form-label">*库存</label>
				<div class="layui-input-block update_shurk" style="width: 80px; margin-right: 10px;">
					<input type="text" name="stock" placeholder="库存" lay-verify="required" class="layui-input" onkeyup="value=value.replace(/[^\d\.]/g,'')" onblur="value=value.replace(/[^\d\.]/g,'')">
				</div>
				<div class="layui-form-mid layui-word-aux">*请输入数字</div>
				<label class="layui-form-label">计量单位</label>
				<div class="layui-input-block" style="float: left; margin-right: 20px; margin-left: 0;">
					<select name="unit">
						<option value=""></option>
						{volist name="$Think.config.units" id="vo"}
						<option value="{$vo}">{$vo}</option>
						{/volist}
					</select>
				</div>
			</div>
			<div class="layui-form-item">
				<label class="layui-form-label">快递类型</label>
				<div class="layui-input-block">
					<input type="radio" name="express_type" value="1" title="快递订单">
					<input type="radio" name="express_type" value="2" title="O2O订单">
					<input type="radio" name="express_type" value="3" title="可快递，可自取" checked>
				</div>
			</div>
			<div class="layui-form-item">
				<label class="layui-form-label">是否推荐</label>
				<div class="layui-input-block">
					<input type="radio" name="is_recommend" value="2" title="是">
					<input type="radio" name="is_recommend" value="1" title="否" checked>
				</div>
			</div>
			<div class="layui-form-item">
				<label class="layui-form-label">是否上架</label>
				<div class="layui-input-block">
					<input type="radio" name="is_on_sale" value="1" title="上架">
					<input type="radio" name="is_on_sale" value="2" title="下架" checked>
				</div>
			</div>

			<div class="layui-form-item" style="width:90%;padding-left: 30px;">
				<script id="content" name="content" type="text/plain"></script>
			</div>
			<div class="layui-form-item update_btnbox" style="text-align: center;margin-left:unset">
				<div class="layui-input-block" style="max-width: unset;float: unset;">
					<button id='change_but' class="layui-btn" lay-submit lay-filter="demo1">立即提交</button>
					<button type="reset" class="layui-btn layui-btn-primary">重置</button>
				</div>
			</div>
		</form>
	</body>

</html>
{block name="script"}
<script type="text/javascript" src="__PUBLIC__/static/js/image.zip.js"></script>
<script type="text/javascript" src="/public/ueditor/ueditor.config.js"></script>
<script type="text/javascript" src="/public/ueditor/ueditor.all.js"></script>
<script type="text/javascript">
	var ue = UE.getEditor('content', {
		serverUrl: "{:url('agent/ueditor/index?cate=goods')}"
	});
</script>
{/block}
<script>
	//平台分类

	//输入框限制
	function keyup(obj) {
		obj.value = obj.value.replace(/[^\d.]/g, ""); //清除“数字”和“.”以外的字符
		obj.value = obj.value.replace(/^\./g, ""); //验证第一个字符是数字而不是.
		obj.value = obj.value.replace(/\.{2,}/g, "."); //只保留第一个. 清除多余的.
		obj.value = obj.value.replace(".", "$#$").replace(/\./g, "").replace("$#$", ".");
	}

	function keyups(obj) {
		var sale_price = $('#sale_price').val();
		if(parseFloat(sale_price) < parseFloat(obj.value)) {
			obj.value = sale_price;
		}

		obj.value = obj.value.replace(/[^\d.]/g, ""); //清除“数字”和“.”以外的字符
		obj.value = obj.value.replace(/^\./g, ""); //验证第一个字符是数字而不是.
		obj.value = obj.value.replace(/\.{2,}/g, "."); //只保留第一个. 清除多余的.
		obj.value = obj.value.replace(".", "$#$").replace(/\./g, "").replace("$#$", ".");
	}

	//提交表单
	function set_content() {
		$.ajax({
			type: "post",
			url: "{:url('shop/goods_add')}",
			data: $('#my_form').serialize(), //表单数据
			success: function(data) {
				if(data.code == 1) {
					layer.msg('添加成功', {
						icon: 1,
						time: 1500 //2秒关闭（如果不配置，默认是3秒）
					}, function() {
						window.parent.location.reload();
						var index = parent.layer.getFrameIndex(window.name); //获取窗口索引  
						parent.layer.close(index);
					});
				} else {
					layer.msg('添加失败'); //保存成功提示
				}
			},
			error: function(data) {
				var a = data;
			}
		});

	}

	//图片上传
	layui.use(['form'], function() {
		var $ = layui.jquery,
			form = layui.form;

		//监听下拉框
		form.on('select(sel_1)', function(data) {

			var cate_id = data.value;

			var cate2_type = platform_2[cate_id];
			var select_htm = '';

			if(cate2_type && cate2_type.length < 1) {
				select_htm = "<option value=''></option>";
			} else {
				for(var i = 0; i < cate2_type.length; i++) {
					select_htm += "<option value='" + cate2_type[i].id + "'>" + cate2_type[i].name + "</option>";
				}
			}

			form.render('select');

		});

		//监听提交
		form.on('submit(demo1)', function(data) {
			$('#change_but').addClass("layui-btn-disabled");
			set_content();
			return false;
		});
	})
</script>